﻿using System;
using System.Collections.Generic;
using System.Text;
using NLBS.Data;
using NLBS.Entity;
using NLBS.Framework;
using NLBS.Views.Admin;

namespace NLBS.Web.UI
{
    public class MiscCommand:ICommand,IMiscAction
    {
        #region Presenter

        private MiscPresenter _presenter;

        public MiscPresenter Presenter
        {
            get
            {
                if (this._presenter == null)
                    _presenter = new MiscPresenter();
                this._presenter.Action = this;
                return _presenter;
            }
        }

        private void PresenterInit()
        {
            this.Presenter.OnActionLoaded();
        }
        #endregion

        private string parameter;
        public MiscCommand(string parameter)
        {
            this.parameter = parameter;
        }

        #region ICommand Members

        public void Excute()
        {
            PresenterInit();
            switch (parameter)
            {
                case "resync_g":
                    this.UpdateGlobalCounterHandler(null, null);
                    break;
                case "resync_c":
                    this.UpdateCategoryCounterHandler(null, null);
                    break;
                case "resync_a":
                    this.UpdateArticleCounterHandler(null, null);
                    break;
                case "resync_u":
                    this.UpdateUserCounterHandler(null, null);
                    break;
                case "clean_u":
                    this.CleanInactiveUserAccountHandler(null, null);
                    break;
                case "clean_vc":
                    this.CleanVisitorCounterHandler(null, null);
                    break;
                case "clean_gb":
                    this.CleanGuestBookEntriesHandler(null, null);
                    break;
            }
        }

        #endregion

        #region IMiscAction Members

        public event EventHandler UpdateCategoryCounterHandler;

        public event EventHandler UpdateArticleCounterHandler;

        public event EventHandler UpdateUserCounterHandler;

        public event EventHandler CleanInactiveUserAccountHandler;

        public event EventHandler CleanVisitorCounterHandler;

        public event EventHandler CleanGuestBookEntriesHandler;

        public event EventHandler UpdateGlobalCounterHandler;

        #endregion
    }
}
